package com.ruoyi.know.service.impl;

import com.ruoyi.know.domain.KnowledgePoints;
import com.ruoyi.know.dto.TopKnowledgePointsDto;
import com.ruoyi.know.mapper.KnowledgePointsMapper;
import com.ruoyi.know.service.IKnowledgePointsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * 知识点Service业务层处理
 *
 * @author ruoyi
 * @date 2025-01-26
 */
@Service
public class KnowledgePointsServiceImpl implements IKnowledgePointsService
{
    @Autowired
    private KnowledgePointsMapper knowledgePointsMapper;

    /**
     * 查询知识点
     *
     * @param knowledgePointId 知识点主键
     * @return 知识点
     */
    @Override
    public KnowledgePoints selectKnowledgePointsByKnowledgePointId(Long knowledgePointId)
    {
        return knowledgePointsMapper.selectKnowledgePointsByKnowledgePointId(knowledgePointId);
    }

    /**
     * 查询知识点列表
     *
     * @param knowledgePoints 知识点
     * @return 知识点
     */
    @Override
    public List<KnowledgePoints> selectKnowledgePointsList(KnowledgePoints knowledgePoints)
    {
        return knowledgePointsMapper.selectKnowledgePointsList(knowledgePoints);
    }

    public List<KnowledgePoints> selectKnowledgePointsListByChapterId(Long chapterId)
    {
        return knowledgePointsMapper.selectKnowledgePointsListByChapterId(chapterId);
    }

    /**
     * 新增知识点
     *
     * @param knowledgePoints 知识点
     * @return 结果
     */
    @Override
    public int insertKnowledgePoints(KnowledgePoints knowledgePoints)
    {
        return knowledgePointsMapper.insertKnowledgePoints(knowledgePoints);
    }

    /**
     * 修改知识点
     *
     * @param knowledgePoints 知识点
     * @return 结果
     */
    @Override
    public int updateKnowledgePoints(KnowledgePoints knowledgePoints)
    {
        return knowledgePointsMapper.updateKnowledgePoints(knowledgePoints);
    }

    /**
     * 批量删除知识点
     *
     * @param knowledgePointIds 需要删除的知识点主键
     * @return 结果
     */
    @Override
    public int deleteKnowledgePointsByKnowledgePointIds(Long[] knowledgePointIds)
    {
        return knowledgePointsMapper.deleteKnowledgePointsByKnowledgePointIds(knowledgePointIds);
    }

    /**
     * 删除知识点信息
     *
     * @param knowledgePointId 知识点主键
     * @return 结果
     */
    @Override
    public int deleteKnowledgePointsByKnowledgePointId(Long knowledgePointId)
    {
        return knowledgePointsMapper.deleteKnowledgePointsByKnowledgePointId(knowledgePointId);
    }

    @Override
    public int getKnowledgePointCount() {
        return knowledgePointsMapper.getKnowledgePointCount();
    }

    /**
     * 查询浏览量前五的知识点
     * @return 包含id、名称、浏览量的Top5列表
     */
    @Override
    public List<TopKnowledgePointsDto> selectTop5PointsByVisit() {
        return knowledgePointsMapper.selectTop5PointsByVisit();
    }

    /**
     * 对特定的类型做清空url的操作
     * @param type 清空的类型
     * @param knowledgePointId 知识点
     * @return 返回清空的结果
     */
    @Override
    public boolean cleanXTypeUrl(Integer type, Long knowledgePointId) {
        return knowledgePointsMapper.setUrlToNull(type,knowledgePointId) > 0;
    }


}
